package com.situ.store.listener;

import javax.servlet.ServletContext;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

@WebListener
public class OnLineNumberListener implements HttpSessionListener {

	@Override
	public void sessionCreated(HttpSessionEvent se) {
		HttpSession session = se.getSession();
		ServletContext application = session.getServletContext();
		Object attr = application.getAttribute("c");
		if (null == attr) {
			application.setAttribute("c", 1);
		} else {
			int c = (int) attr;
			application.setAttribute("c", ++c);
		}
	}

	@Override
	public void sessionDestroyed(HttpSessionEvent se) {
		HttpSession session = se.getSession();
		ServletContext application = session.getServletContext();
		int c = (int) application.getAttribute("c");
		application.setAttribute("c", --c);
	}

}
